/**    
 * 文件名：Ex4InvertLut.java    
 *    
 * 版本信息：    
 * 日期：2014年3月10日    
 * xyj 足下 xyj 2014     
 * 版权所有    
 *    
 */
package opencvtest.chapter04;

import static com.googlecode.javacv.cpp.opencv_core.CV_8U;
import static com.googlecode.javacv.cpp.opencv_highgui.CV_LOAD_IMAGE_GRAYSCALE;
import static opencvtest.OpenCVUtils.loadAndShowOrExit;
import static opencvtest.OpenCVUtils.show;

import java.io.File;

import com.googlecode.javacv.cpp.opencv_core.CvMat;
import com.googlecode.javacv.cpp.opencv_core.IplImage;

/**
 * Creates inverted image by inverting its look-up table. Example for section
 * "Applying look-up table to modify image appearance" in Chapter 4.
 */
public class Ex4InvertLut {

    public static void main(String[] args) {

        // Load image as a gray scale
        IplImage src = loadAndShowOrExit(new File("data/group.jpg"), CV_LOAD_IMAGE_GRAYSCALE);

        // Create inverted lookup table
        CvMat lut = CvMat.create(1, 256, CV_8U);
        for (int i = 0; i <= 255; i++) {
            lut.put(i, 255 - i);
        }

        // Apply look-up
        IplImage dest = Histogram1D.applyLookup(src, lut);

        // show inverted image;
        show(dest, "Inverted LUT");

    }

}
